package com.restaurant.serviceimpl;

import java.util.List;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.restaurant.domain.Venderdetails;
import com.restaurant.service.VenderdetailsService;

public class VenderdetailsServiceImpl implements VenderdetailsService {

   private HibernateTemplate hibernateTemplate;

   @Autowired
   public void setSessionFactory(SessionFactory sessionFactory){
       this.hibernateTemplate = new HibernateTemplate(sessionFactory);
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Venderdetails addOrModify( Venderdetails objVenderdetails ) {
       return ( Venderdetails ) hibernateTemplate.merge( objVenderdetails );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Venderdetails deleteRecord( Venderdetails objVenderdetails ) {
       hibernateTemplate.delete( objVenderdetails );
       return objVenderdetails;
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Venderdetails modifyRecord( Venderdetails objVenderdetails ) {
       return ( Venderdetails ) hibernateTemplate.merge( objVenderdetails );
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Venderdetails> loadAll() {
       return (List<Venderdetails>)hibernateTemplate.findByNamedQuery( "Venderdetails.findAll");
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Venderdetails loadByPrimaryKey( Long primaryKey ) {
       return (Venderdetails) hibernateTemplate.get( Venderdetails.class, primaryKey );
   }

   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public Venderdetails deleteByPrimaryKey( Long primaryKey ) {
       return deleteRecord(loadByPrimaryKey(primaryKey));
   }

   @SuppressWarnings("unchecked")
   @Override
   @Transactional(propagation = Propagation.REQUIRED, isolation=Isolation.DEFAULT)
   public List<Venderdetails> loadByHql(String query) {
       return ( List<Venderdetails> ) hibernateTemplate.find( query );
   }
}